import { ImageProcessType } from '@utils/image-process/image-process-type.enum';

export class ProcessMenuTreeNode {
  public title = '';
  public type: ImageProcessType | null = null;
  public children: ProcessMenuTreeNode[] | null = null;
  public isLeaf = true;
  constructor(options: TreeNodeOptions) {
    this.title = options.title;
    this.type = options.type;
    this.children = options.children || null;
    this.isLeaf = Boolean(options.isLeaf) && this.children === null;
  }

  appendChildren(nodes: ProcessMenuTreeNode[]) {
    this.isLeaf = false;
    if (this.isLeaf || !this.children) {
      this.children = [...nodes];
    } else {
      this.children.push(...nodes);
    }
  }
}

export interface TreeNodeOptions {
  title: string;
  type: ImageProcessType | null;
  children?: ProcessMenuTreeNode[];
  isLeaf?: boolean;
}
